package controller

import (
	"encoding/json"
	"github.com/gin-gonic/gin"
	"house-property/common"
	"house-property/model"
	"log"
	"strconv"
)

func Property(ctx *gin.Context){
	DB:=common.InitDB()
	b, _ := ctx.GetRawData()
	var m map[string]string
	_ = json.Unmarshal(b, &m)
	var sta []model.Hou_property
	DB.Find(&sta)
	log.Println(sta)
	ctx.JSON(200,sta)
}
func Deletepro(ctx *gin.Context) {
	DB:=common.InitDB()
	hnum:=ctx.Query("id");
	if hnum!=""{
		ctx.JSON(200, gin.H{
			"code":200,
		})
	}
	var sta model.Hou_property
	DB.Where("Hnum = ?",hnum).Delete(&sta)
}
func Modifypro(ctx *gin.Context){
	DB := common.InitDB()
	b, _ := ctx.GetRawData()
	var m map[string]string
	_ = json.Unmarshal(b, &m)
	hnum := m["hnum"]
	harea := m["harea"]
	hallocation := m["hallocation"]
	urentmeter := m["urentmeter"]
	u,_:=strconv.Atoi(urentmeter )
	newsta2 := model.Hou_property{
		Hnum: hnum,
		Harea: harea,
		Urentmeter: u,
		Hallocation: hallocation,
	}
	DB.Create(&newsta2)
	//返回结果
	ctx.JSON(200,gin.H{
		"code":200,
		"msg":newsta2,
	})
}
